﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace drcoderz.com.gauges.complex
{
    public class ComplexGauge : Control
    {
        private RotateTransform gaugeRotation;

        public ComplexGauge()
        {
            this.DefaultStyleKey = typeof(ComplexGauge);
        }

        public override void OnApplyTemplate()
        {
            gaugeRotation = this.GetTemplateChild("gaugeRotation") as RotateTransform;
            gaugeRotation.Angle = GaugeValue;

            base.OnApplyTemplate();
        }

        private string GaugeLabel
        {
            get { return (string)GetValue(GaugeLabelProperty); }
            set { SetValue(GaugeLabelProperty, value); }
        }

        // Using a DependencyProperty as the backing store for GaugeLabel.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty GaugeLabelProperty =
            DependencyProperty.Register("GaugeLabel", typeof(string), typeof(ComplexGauge), new PropertyMetadata("0"));

        public double GaugeValue
        {
            get { return (double)GetValue(GaugeValueProperty); }
            set
            {

                var angleCalc = value > 900 ? 900 : (value < 0 ? 0 : value);
                
                if (value <= 900 && value >=0)
                    GaugeLabel = value.ToString();

                angleCalc = (angleCalc * 0.30) + 1;

                SetValue(GaugeValueProperty, angleCalc);
                
                if (gaugeRotation != null)
                    gaugeRotation.Angle = angleCalc;

            }
        }

        // Using a DependencyProperty as the backing store for GaugeValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty GaugeValueProperty =
            DependencyProperty.Register("GaugeValue", typeof(double), typeof(ComplexGauge), new PropertyMetadata(null));




        public string UOM
        {
            get { return (string)GetValue(UOMProperty); }
            set { SetValue(UOMProperty, value); }
        }

        // Using a DependencyProperty as the backing store for UOM.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UOMProperty =
            DependencyProperty.Register("UOM", typeof(string), typeof(ComplexGauge), new PropertyMetadata("MPH"));




        public string SubLabel
        {
            get { return (string)GetValue(SubLabelProperty); }
            set { SetValue(SubLabelProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SubLabel.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SubLabelProperty =
            DependencyProperty.Register("SubLabel", typeof(string), typeof(ComplexGauge), new PropertyMetadata("SPORT"));

        

        public Brush ThinArchColor
        {
            get { return (Brush)GetValue(ThinArchColorProperty); }
            set { SetValue(ThinArchColorProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ThinArchColor.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ThinArchColorProperty =
            DependencyProperty.Register("ThinArchColor", typeof(Brush), typeof(ComplexGauge), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(255, 67,200,248))));



        public Brush HandColor
        {
            get { return (Brush)GetValue(HandColorProperty); }
            set { SetValue(HandColorProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HandColor.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HandColorProperty =
            DependencyProperty.Register("HandColor", typeof(Brush), typeof(ComplexGauge), new PropertyMetadata(new SolidColorBrush(Colors.Red)));



        public Brush GaugeLabelColor
        {
            get { return (Brush)GetValue(GaugeLabelColorProperty); }
            set { SetValue(GaugeLabelColorProperty, value); }
        }

        // Using a DependencyProperty as the backing store for GaugeLabelColor.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty GaugeLabelColorProperty =
            DependencyProperty.Register("GaugeLabelColor", typeof(Brush), typeof(ComplexGauge), new PropertyMetadata(new SolidColorBrush(Colors.White)));

        

        

    }
}
